package leetcode;

public class Leetcode415 {
    public String addStrings(String num1, String num2) {
        StringBuilder sb = new StringBuilder();
        int n1 = num1.length()-1;
        int n2 = num2.length()-1;
        int carry = 0;
        while(n1>=0||n2>=0){
            int tmpNum1 = n1>=0?num1.charAt(n1)-'0':0;
            int tmpNum2 = n2>=0?num2.charAt(n2)-'0':0;
            int value = (tmpNum1+tmpNum2+carry)%10;
            carry = (tmpNum1+tmpNum2+carry)/10;
            sb.append(value);
            n1--;
            n2--;
        }
        if(carry==1){
            sb.append(1);
        }
        return sb.reverse().toString();
    }
}
